
import DialogBaseUI from "../custom/DialogBaseUI";
import {HeroData} from "../data/HeroData";
import {ToolUtils} from "../util/ToolUtils";

const {ccclass, property} = cc._decorator;
@ccclass
export class UserInfoUI extends DialogBaseUI {
    @property(cc.Sprite)
    headSprite:cc.Sprite = null;
    @property(cc.Label)
    nameLabel:cc.Label = null;
    @property(cc.Label)
    idLabel:cc.Label = null;
    @property(cc.Label)
    goldLabel:cc.Label = null;
    @property(cc.Label)
    giftLabel:cc.Label = null;
    @property(cc.Label)
    diamondLabel:cc.Label = null;

    onEnable(){
        super.onEnable();
        this.updateName();
        this.updateID();
        this.updateDiamond();
        this.updateBodyGold();
        this.updateGift();
        this.updateHead();
    }

    private updateName(){
        if(this.nameLabel == null) return;
        this.nameLabel.string = HeroData.nickname;
    }

    private updateID(){
        if(this.idLabel == null) return;
        this.idLabel.string = HeroData.userid;
    }

    private updateDiamond(){
        if(this.diamondLabel == null) return;
        ToolUtils.numToShort(HeroData.diamond,this.diamondLabel,83);
    }

    private updateBodyGold(){
        if(this.goldLabel == null) return;
        ToolUtils.numToShort(HeroData.bodygold,this.goldLabel,83);
    }
    private updateGift(){
        if(this.giftLabel == null) return;
        ToolUtils.numToShort(HeroData.gift,this.giftLabel,83);
    }

    private updateHead(){
        ToolUtils.loadNetImage(HeroData.headimg,this.headSprite)
    }
}